<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateFinanceBillsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('finance_bills', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('bill_id', 32)->unique()->comment('流水id号');
            $table->integer('bill_uid')->comment('记录人员id');
            $table->tinyInteger('bill_type')->default(1)->comment('记录类型 1支出 2收入');
            $table->tinyInteger('bill_channel')->default(1)->comment('记录来源 1充值 2提现 3代付');
            $table->string('channel_id')->comment('来源类型订单号');
            $table->decimal('bill_amt', 16, 6)->comment('流水金额');
            $table->decimal('cur_available', 16, 6)->default(0)->comment('账户可用余额');
            $table->string('bill_info', 500)->comment('流水详情');
            $table->index('bill_id');
            $table->index('bill_uid');
            $table->index(['bill_type', 'bill_channel', 'channel_id']);
            $table->unique(['bill_uid', 'channel_id']);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('finance_bills');
    }
}
